package com.quintal.androidtouchcloud.mainActivities;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Html;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.quintal.androidtouchcloud.R;

public class TagUpdatedActivity extends Activity {
	
	final static private String USER_KEY = "user";
	final static private String TAG_KEY = "nfc_id";
	final static private String PRIVACY_KEY = "privacy";
	private static final String MODULE = "Tag Updated Acitivity";
	final static private String TAG_DATE = "tag_date";
	
	private String _share_link;
	private String _user;
	private String _privacy;
	private String _nfc_id;
	private String _tag_date;

	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		getActionBar().setDisplayShowHomeEnabled(false);
		getActionBar().setDisplayShowTitleEnabled(false);
		getActionBar().hide();
		setContentView(R.layout.tag_updated_layout);
		Intent i = getIntent();
		_share_link = getIntent().getStringExtra("share_link");
		_user 	  = getIntent().getIntExtra(USER_KEY, 0)+"";
		_privacy    = getIntent().getStringExtra(PRIVACY_KEY);
		_nfc_id	  = getIntent().getStringExtra(TAG_KEY);
		_tag_date = getIntent().getStringExtra(TAG_DATE);
		TextView tag_tip = (TextView)findViewById(R.id.tag_tip);
		Log.e(MODULE, "user id "+_user);
		String first = "<font color='#E44C43'>"+getString(R.string.tag_tip_title)+": </font>";
		String next = getString(R.string.tag_tip);
		tag_tip.setText(Html.fromHtml(first + next));
		String success_msg = getString(R.string.tag_success);
		String file_folder = _share_link.contains("/sh/") ?getString(R.string.folder):getString(R.string.file);
		TextView tag_success = (TextView)findViewById(R.id.tag_success_msg);
		tag_success.setText(file_folder+success_msg);
		initDBButton();
		initQuestionnaireButton();
	}

	@Override
	public void onResume(){
		super.onResume();
	}
	@Override
	public void onStop(){
		super.onStop();
		finish();
	}
	@Override
	public void onPause(){
		super.onPause();
		finish();
	}
	private void initDBButton(){
		Button gotoDB = (Button)findViewById(R.id.tag_update_gotoDB);
		gotoDB.setOnTouchListener(new View.OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent arg1) {
				switch(arg1.getAction()){
				case MotionEvent.ACTION_DOWN:
					v.setBackgroundColor(Color.parseColor("#247AE0"));
					break;
				case MotionEvent.ACTION_UP:
					v.setBackgroundColor(Color.parseColor("#FF2126"));
					closeApp();
					break;
				}
				return false;
			}
		});
	}
	private void initQuestionnaireButton(){
		Button goto_questionaire = (Button)findViewById(R.id.go_to_questionnaire);
		goto_questionaire.setOnTouchListener(new View.OnTouchListener() {

			@Override
			public boolean onTouch(View v, MotionEvent arg1) {
				switch(arg1.getAction()){
				case MotionEvent.ACTION_DOWN:
					v.setBackgroundResource(R.drawable.button_background_pressed);
					((TextView)v).setTextColor(Color.parseColor("#FF0000"));
					break;
				case MotionEvent.ACTION_UP:
					v.setBackgroundResource(R.drawable.button_background);
					((TextView)v).setTextColor(Color.parseColor("#FFFFFF"));
					Intent quest_int = new Intent(getApplicationContext(),UserReportActivity.class);
					quest_int.putExtra(TAG_KEY, _nfc_id);
					quest_int.putExtra(USER_KEY, _user);
					quest_int.putExtra(PRIVACY_KEY, _privacy);
					quest_int.putExtra(TAG_DATE, _tag_date);
					startActivity(quest_int);
					break;
			}
				return false;
		}
		});
	}
	private void closeApp(){
		Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.dropbox.android");
		startActivity(LaunchIntent);
		this.finish();
	}
}
